home *** CD-ROM | disk | FTP | other *** search
/ MacFormat UK 203 / MF_UK_203_1.iso / pc / DiscContents / In the mag / Widgets / URL Compression Widget 1.0 / Widget / isgd.wdgt / main.js < prev   
Encoding:
JavaScript  |  2008-10-29  |  3.1 KB  |  142 lines

  1. /* 
  2.  This file was generated by Dashcode.  
  3.  You may edit this file to customize your widget or web page 
  4.  according to the license.txt file included in the project.
  5.  */
  6.  
  7. //
  8. // Function: load()
  9. // Called by HTML body element's onload event when the widget is ready to start
  10. //
  11. function load()
  12. {
  13.     dashcode.setupParts();
  14. }
  15.  
  16. //
  17. // Function: remove()
  18. // Called when the widget has been removed from the Dashboard
  19. //
  20. function remove()
  21. {
  22.     // Stop any timers to prevent CPU usage
  23.     // Remove any preferences as needed
  24.     // widget.setPreferenceForKey(null, dashcode.createInstancePreferenceKey("your-key"));
  25. }
  26.  
  27. //
  28. // Function: hide()
  29. // Called when the widget has been hidden
  30. //
  31. function hide()
  32. {
  33.     $("#cancel").hide();
  34.     $("#shortURL").val("");
  35.     $("#shortURL").hide();
  36.     $("#longURL").val("");
  37.     $("#button").show();
  38. }
  39.  
  40. //
  41. // Function: show()
  42. // Called when the widget has been shown
  43. //
  44. function show()
  45. {
  46.     $("#cancel").hide();
  47.     $("#shortURL").hide();
  48. }
  49.  
  50. //
  51. // Function: sync()
  52. // Called when the widget has been synchronized with .Mac
  53. //
  54. function sync()
  55. {
  56.     // Retrieve any preference values that you need to be synchronized here
  57.     // Use this for an instance key's value:
  58.     // instancePreferenceValue = widget.preferenceForKey(null, dashcode.createInstancePreferenceKey("your-key"));
  59.     //
  60.     // Or this for global key's value:
  61.     // globalPreferenceValue = widget.preferenceForKey(null, "your-key");
  62. }
  63.  
  64. //
  65. // Function: showBack(event)
  66. // Called when the info button is clicked to show the back of the widget
  67. //
  68. // event: onClick event from the info button
  69. //
  70. function showBack(event)
  71. {
  72.     var front = document.getElementById("front");
  73.     var back = document.getElementById("back");
  74.  
  75.     if (window.widget) {
  76.         widget.prepareForTransition("ToBack");
  77.     }
  78.  
  79.     front.style.display = "none";
  80.     back.style.display = "block";
  81.  
  82.     if (window.widget) {
  83.         setTimeout('widget.performTransition();', 0);
  84.     }
  85. }
  86.  
  87. //
  88. // Function: showFront(event)
  89. // Called when the done button is clicked from the back of the widget
  90. //
  91. // event: onClick event from the done button
  92. //
  93. function showFront(event)
  94. {
  95.     var front = document.getElementById("front");
  96.     var back = document.getElementById("back");
  97.  
  98.     if (window.widget) {
  99.         widget.prepareForTransition("ToFront");
  100.     }
  101.  
  102.     front.style.display="block";
  103.     back.style.display="none";
  104.  
  105.     if (window.widget) {
  106.         setTimeout('widget.performTransition();', 0);
  107.     }
  108. }
  109.  
  110. if (window.widget) {
  111.     widget.onremove = remove;
  112.     widget.onhide = hide;
  113.     widget.onshow = show;
  114.     widget.onsync = sync;
  115. }
  116.  
  117.  
  118. function compressHandler(event)
  119. {
  120.     var longurl = document.getElementById("longURL");
  121.     if (longurl.value != "") 
  122.     {
  123.         $.get("http://is.gd/api.php?longurl="+escape(longurl.value), function(short){
  124.             $("#shortURL").val(short);
  125.         });
  126.         $("#button").hide();
  127.         $("#cancel").show();
  128.         $("#shortURL").show();
  129.     }
  130. }
  131.  
  132.  
  133. function cancelURL(event)
  134. {
  135.     $("#cancel").hide();
  136.     $("#shortURL").val("");
  137.     $("#shortURL").hide();
  138.     $("#longURL").val("");
  139.     $("#button").show();
  140.     
  141. }
  142.